package com.work.account.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.work.account.entity.Account;
import com.work.account.repository.AccountDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AccountService {

    @Resource
    private AccountDao accountDao;


    public void reduce(String userId, int money){
        QueryWrapper<Account> wrapper = new QueryWrapper<>();
        wrapper.setEntity(new Account().setUserId("xhx"));
        Account account = accountDao.selectOne(wrapper);
        account.setMoney(account.getMoney() - money);

        accountDao.updateById(account);
    }

    public void add(String userId, int money){
        QueryWrapper<Account> wrapper = new QueryWrapper<>();
        wrapper.setEntity(new Account().setUserId("xhx"));
        Account account = accountDao.selectOne(wrapper);
        account.setMoney(account.getMoney() + money);

        accountDao.updateById(account);
    }
}
